import 'package:flutter/material.dart';
import 'package:treasure/components/setting_item.dart';
import 'package:treasure/global.dart';
import 'package:treasure/routes.dart';

class HomeDrawer extends StatelessWidget {
  const HomeDrawer({super.key});

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: MediaQuery.removePadding(
        context: context,
        //移除抽屉菜单顶部默认留白
        removeTop: true,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.only(top: 38.0),
              child: Row(
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 16.0),
                    child: ClipOval(
                      child: Image.asset(
                        Global.user.avatar,
                        width: 80,
                      ),
                    ),
                  ),
                   Text(
                    Global.user.nickName,
                    style: const TextStyle(fontWeight: FontWeight.bold),
                  )
                ],
              ),
            ),
            Expanded(
              child: ListView(children: _getDrawerItems()),
            ),
          ],
        ),
      ),
    );
  }

  List<SettingItem> _getDrawerItems() {
    return const <SettingItem>[
      SettingItem(icon: Icons.settings, title: '设置', uri: MyRouter.settingPage),
      SettingItem(icon: Icons.info, title: '关于', uri: MyRouter.aboutPage),
    ];
  }
}
